new Vue({
    el:"#app",
    data(){
      var password = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('不能为空'));
        }  else {
          callback();
        }
      };
      var repassword = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入密码'));
        } else if (value !== this.registerFrom.password) {
          callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
      };
      return {
        registerFrom:{
          account:'',
          password:'',
          repassword:''
        },

        registerRules:{
          password:[{ pattern: /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,18}$/, message: '密码中必须有字母加数字，不得小于6位',trigger: 'blur' },
            {validator: password, trigger: 'blur' }
          ],
          repassword:{validator: repassword, trigger: 'blur' }
        }
      }
    },
    methods:{
      register(){
        var that = this;
        this.$refs.registerFrom.validate((valid) => {
          if (valid){
            $.ajax({
              url: '/register.do',
              data: that.registerFrom,
              dataType: 'json',
              type: 'post',
              success: function (data) {
                if (data.code == 200) {
                  window.location.href = "/login.html"
                }
                if (data.code == 500) {
                  that.$message.error(data.msg);
                }
              },
              error: function () {
                that.$message.error("网络问题！！！！！！！");
              }
            })
          }else {
            // this.$message.error("")
            return false;
          }


        })
      },
      toLogin(){
        window.location.href = "/login.html";
      }
    }
  })